package at.com.vn.chess.dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;

import at.com.vn.chess.entity.User;

public class UserDao extends BaseDao {

	/** Getting the Session Factory and session */
	private Session sess = null;

	public UserDao() {
		super();
		sess = super.getSess();
	}

	public List<User> findAllUser() {
		return sess.createQuery("from User").list();
	}

	public User findUser(String UserId) {
		Query q = sess.createQuery("from User where user_id = :UserId ");
		q.setParameter("UserId", UserId);
		if (q.list() != null && q.list().size() > 0) {
			return (User) q.list().get(0);
		}
		return null;
	}

	public User registUser(User user) {
		sess.save(user);
		return user;
	}

	public User updateUser(User user) {
		sess.update(user);
		return user;
	}
}